<template>
	<view class="wrap">
		<view class="search-box">
			<u-search placeholder="搜索门店" shape="square" v-model="searchData.storeName" @search="onSearch" :showAction="false"/>
			<view class="custom-btn" @click="onSearch">搜索</view>
		</view>
		<view class="my-list">
			<u-list v-if="dataList.length > 0" :height="swiperHeight" @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in dataList" :key="item.id">						  
					<view class="item lh-50" @click="$u.route('/pages/shop/default/edit', { id: item.id, type: '1' })">
						<view class="fweigh-600">{{item.storeName}}</view>
						<view class="flex align-center">
							<view class="w-100">
								<view class="text-gray fsize-28">
									<view class="">
										<text class="">{{item.linkMan}}</text>
										<text class="ml-10">{{item.mobile}}</text>
									</view>
									<view class="">
										<uni-icons custom-prefix="iconfont" type="icon-daodianditu" :color="iconColor" />
										<text class="text-gray ml-4">{{item.address}}</text>
									</view>
									<view class="">
										<uni-icons custom-prefix="iconfont" type="icon-time" :color="iconColor" />
										<text class="text-gray ml-4">{{item.openingTime}} - {{item.closingTime}}</text>
									</view>
								</view>
							</view>
							<view class="shink0 ml-10">
								<u-avatar 
									:src="item.logoImage" 
									default-url="/static/logo.png"
									size="80" 
									shape="square">
								</u-avatar>
							</view>
						</view>
					</view>
				</u-list-item>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length === 0">
			<u-empty icon-size="100" text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>	
	import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		mixins:[listHeightMixin],
		data() {
			return {
				dataList: [],
				searchData: {
					storeName:'',
					page: 1,
					limit: 20
				},
				iconColor:'#aaaaaa',
				loadmore:{
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
			}
		},
		
		onLoad() {
			this.getPageList()
			uni.$on('upStoreList', obj=>{
				this.onSearch()
			})
		},
		onUnload() {
			uni.$off('upStoreList')
		},
		methods: {
			onSearch() {
				this.dataList = []
				this.searchData.page = 1
				this.getPageList()
			},
			getPageList(){
				this.$reqPost('StoreGetPageList',this.searchData).then(res=>{
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore'
						this.searchData.page++
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore'
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getPageList()
				}
			}
		}

	}
</script>

<style lang="scss" scoped>

</style>
